
// * 导入所有router
const metaRouters = import.meta.webpackContext("../router", {
    recursive: false,
    regExp: /\.jsx$/
})
// * 处理路由
const routerArray = [];
let uniPath = []
metaRouters.keys().forEach(key => {
    for (const [, childValue] of Object.entries(metaRouters(key))) {
        childValue &&  childValue.forEach((it) => {
            const { path = '' } = it
            uniPath.includes(path) ? console.error(`路由path存在重复：${path}`) : uniPath.push(path);
        });
        routerArray.push(...childValue)
    }
})
const rootRouter = [
    {
        path: "/",
        element: <Navigate to="/login" />
    },
    ...routerArray,
    {
        path: "*",
        element: <Navigate to="/404" />
    }
];

const $globalRouter = () => {
    const routes = useRoutes(rootRouter)
    return routes
};

export {
    $globalRouter,
    rootRouter
} 
